﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 09/04/2009
// Time: 23:46
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of ProductGroup.
	/// </summary>
	public class ProductGroup : common.DefaultClass, common.IClass
	{
		#region private declarations
			private string _group_name;
			private string _group_company_id;
		#endregion
		
		#region properties
		public string name 
		{
			get { return _group_name; }
			set { _group_name = value; }
		}
		
		public string companyId 
		{
			get { return _group_company_id; }
			set { _group_company_id = value; }
		}
			
		#endregion
		
		public ProductGroup()
		{
			gsql.table = "common.product_group";
			_sequence  = "common.product_group_product_group_id_seq";
		}
		
		public void clear()
		{
			_id = string.Empty;
			_group_name = string.Empty;
			_group_company_id = string.Empty;
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id		= dr["product_group_id"].ToString();
			_group_name	= dr["product_group_name"].ToString();
			_group_company_id	= dr["product_group_company_id"].ToString();
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id, "product_group_id");
			gsql.setValue(_group_name, "product_group_name");
			gsql.setValue(_group_company_id, "product_group_company_id");
		}	
	}
	
	public class ProductGroups : common.DefaultList, common.IList
	{
		public ProductGroups()
		{
			gsql.table = "common.product_group";
		}
		
		/*public List<ProductGroup> items
		{
			get { return items; }
		}*/
		
		public ProductGroup get(Int32 index)
		{
			return (ProductGroup)items[index];
		}
		
		public ProductGroup get()
		{
			return (ProductGroup)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "product_group_company_id = "+Information.companyId;
			gsql.additionalWhere = "ORDER BY product_group_name";
			
			return mountList();
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				ProductGroup p = new ProductGroup();
				p.get(gsql.getRow(i));
				items.Add(p);
			}
			return true;
		}
	}	
}
